package com.hnas.sys.orm;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import com.hnas.core.util.StringUtil;
import com.hnas.sys.domain.ResourceStatus;

//import freemarker.template.utility.StringUtil;
@Entity
@Table(name="sys_user"
 
, uniqueConstraints = {@UniqueConstraint(columnNames="account")}
)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="user_type",
discriminatorType=DiscriminatorType.STRING
)
@DiscriminatorValue("Basic_User")
public class BasicUser   implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7445448044034775255L;
	// Fields    
    @Id @GeneratedValue(strategy=IDENTITY)    
    @Column(name="id", nullable=false)
     private long id;
     private String account;
     private String password;
     private String name;
     @Column(name="phone")
     private String telephone;
     private String email;
     @Transient
     private ResourceStatus status;
     @Column(name="status", length=5)
     private String statusStr;
     @Column(name="is_system_admin")
     private Integer isSystemAdmin;
//     @Column(name="user_Type")
//     private String userType;
     private long operator;
     @Column(name="update_Time")
     private String updateTime;
     @Column(name="last_Login")
     private String lastLogin;
 	@Column(name = "user_role", columnDefinition = "text")
 	private String userRole; // 用户数据权限
 	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String phone) {
		this.telephone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

	public String getStatusStr() {
		return statusStr;
	}

	public Integer getIsSystemAdmin() {
		return isSystemAdmin;
	}
	public void setIsSystemAdmin(Integer isSystemAdmin) {
		this.isSystemAdmin = isSystemAdmin;
	}
//	public String getUserType() {
//		return userType;
//	}
//	public void setUserType(String userType) {
//		this.userType = userType;
//	}
	public long getOperator() {
		return operator;
	}
	public void setOperator(long operator) {
		this.operator = operator;
	}
	public String getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}
	public String getLastLogin() {
		return lastLogin;
	}
	public void setLastLogin(String lastLogin) {
		this.lastLogin = lastLogin;
	}
	

    public String getUserRole() {
		return userRole;
	}
	public void setUserRole(String userRole) {
		this.userRole = userRole;
	}
	public void setStatusStr(String statusStr) {
        this.statusStr = statusStr;
        if(StringUtil.isEmpty(statusStr)) {
        	status = null;
        } else {
        	status = ResourceStatus.valueOfAlias(statusStr);
        }
    }
    
    /**
	 * @return the status
	 */
//    @Transient
	public ResourceStatus getStatus() {
		if(!StringUtil.isEmpty(statusStr)) {
			return ResourceStatus.valueOfAlias(statusStr);
		}
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(ResourceStatus status) {
		this.status = status;
		if(null != status) {
			this.statusStr = status.getAlias();
		}
	}
}
